package com.chase.framerwork.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.map.ListOrderedMap;
import org.springframework.stereotype.Service;

import com.chase.framerwork.dao.CruiserDao;

@Service("cruiseServiceImpl")
public class CruiseServiceImpl extends BaseServiceImpl implements CruiserService
{

	private CruiserDao cruiserDao;

	@Override
	public List<Map<String, Object>> DDL(String sql)
	{
		cruiserDao.getJdbcTemplate().execute(sql);
		
		return null;
	}

	@Override
	public List<Map<String, Object>> DML(String sql)
	{
		List<Map<String, Object>> list = new ArrayList<>();
		if (sql.trim().startsWith("select"))
		{
			list = cruiserDao.getJdbcTemplate().queryForList(sql);
		}
		else if (sql.trim().startsWith("insert") || sql.trim().startsWith("delete") || sql.trim().startsWith("update"))
		{
			int result = cruiserDao.getJdbcTemplate().update(sql);

			Map<String, Object> map = new ListOrderedMap();

			map.put("status", "success");
			map.put("result", result);

			list.add(map);
		}
		else
		{
			list = DDL(sql);
		}
		return list;
	}

	public CruiserDao getCruiserDao()
	{
		return cruiserDao;
	}

	@Resource
	public void setCruiserDao(CruiserDao cruiserDao)
	{
		this.cruiserDao = cruiserDao;
	}

	@Resource
	public void setBaseDao(CruiserDao cruiserDao)
	{
		super.setBaseDao(cruiserDao);
	}
}
